<?php
/**
 * Created by PhpStorm.
 * User: xjwan
 * Date: 16-4-29
 * Time: 下午5:23
 */

namespace Admin\Controller;

use Qiniu\Auth;
use Think\Controller;
use Qiniu\Storage\BucketManager;

class QiniuController extends Controller
{
    /*
     * 删除文件
     * ＠wan
     * */
    public function delFile($id){
        vendor('qiniu.autoload');
        $accessKey = 'KN1B6wd3Gl1cRKpywQExkr1bh9FSAIPCzizIq77R';
        $secretKey = 'JkN4e_sfUxqwna1mXgZ4XIiiJvo-_VIN2HNWjGuZ';

        //初始化Auth状态
        $auth = new Auth($accessKey, $secretKey);

        //初始化BucketManager
        $bucketMgr = new BucketManager($auth);
        //你要测试的空间， 并且这个key在你空间中存在
        $bucket = 'dici';
        $key = base64_decode($id);
        var_dump($key);

        //删除$bucket 中的文件 $key
        $err = $bucketMgr->delete($bucket, $key);
        echo "\n====> delete $key : \n";
        if ($err !== null) {
            var_dump($err);
        } else {
            echo "Success!";
        }


    }
}